package wan.moneybook.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import wan.moneybook.bean.Row;
import wan.moneybook.sql.SqlMapper;

import com.ibatis.sqlmap.client.SqlMapClient;

public class SaveHandler implements Handler {

	@Override
	public String process(HttpServletRequest request,
			HttpServletResponse response) throws Throwable {

		Row bean = new Row(request);

		SqlMapClient sqlMap = SqlMapper.getInstance();

		if (bean.getSeq() == 0) {
			int seq = (Integer)sqlMap.insert("insertRecord", bean);
			request.setAttribute("data", seq);
			return "/WEB-INF/jspf/response.jsp";
		} else {
			sqlMap.update("updateRecord", bean);
			return null;
		}
	}
}
